
Imports System
Imports System.Web.UI
Imports System.Collections
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for groups_main.
	''' </summary>
	Public Partial Class group_categories
		Inherits BaseWebPage
		Protected hlCreateGroup As System.Web.UI.WebControls.HyperLink
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			Me.pageTemplate.PageTitle = PageTitles.GROUP_CATS_PAGE

			Dim user As User = Me.LoggedUser
			If user = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			Me.initPageTitles(Constants.GROUP_CATEGORIES, "", frmGroupCategories, Nothing, htPageConstants)
			Me.initAdvertisements(frmGroupCategories, Nothing)

			'init tabs
			ucGroupTabs.ActiveTab = 2
			ucGroupTabs.PageName = Constants.GROUP_CATEGORIES

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			Dim strEnterPressedScript As String = "<script language='javascript'>" + Environment.NewLine + "function KeyDownHandler(btn){" + Environment.NewLine + "" & Chr(9) & "if (event.keyCode == 13){" + Environment.NewLine + "" & Chr(9) & "" & Chr(9) & "event.returnValue=false;" + Environment.NewLine + "" & Chr(9) & "" & Chr(9) & "event.cancel = true;" + Environment.NewLine + "" & Chr(9) & "" & Chr(9) & "btn.click();" + Environment.NewLine + "" & Chr(9) & "}" + Environment.NewLine + "}" + Environment.NewLine + "</script>" + Environment.NewLine
			Me.RegisterClientScriptBlock("EnterPressed", strEnterPressedScript)
			txtKeyword.Attributes.Add("onKeyDown", "KeyDownHandler(_ctl0_btnSearch)")

			Dim categoriesCount As Integer = Constants.CATEGORIES.List.Count
			Dim tmpCategory1 As Categories.Category
			Dim tmpCategory2 As Categories.Category

			Dim grp As Group = Groups.GetFeaturedGroup()
			If grp <> Nothing Then
				' get group image
				Dim grpPicture As GroupPicture = grp.DefaultPicture
				If grpPicture <> Nothing Then
					hlGroupPicture.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(grpPicture, "../")
				Else
					hlGroupPicture.ImageUrl = "../images/default_thumbnail.gif"
				End If
				hlGroupPicture.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlGroupPicture.ToolTip = grp.Name
				hlGroupName.Text = grp.Name
				hlGroupName.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

				hlCategory.Text = Constants.CATEGORIES.GetCategoryByID(grp.CatID).Name
				hlCategory.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + grp.CatID

				hlViewGroup.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlJoinGroup.NavigateUrl = "../" + Constants.CONFIRM_JOIN_GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

				If Not grp.PublicGroup Then
					lblGroupType.Text = Me.GetPageConstText(htPageConstants, "CONST_Private_TEXT")
				End If

				lblCreated.Text = grp.CreationDate.Day + "/" + grp.CreationDate.Month + "/" + grp.CreationDate.Year
				lblLocation.Text = grp.City + ", " + Constants.COUNTRIES.GetCountryByID(grp.CountryID).Name
				If grp.ShortAbout <> Nothing AndAlso grp.ShortAbout.Length > 0 Then
					lblAbout.Text = Server.HtmlEncode(getBeginning(grp.ShortAbout, Constants.MAX_GROUP_ABOUT_LENGTH))
				Else
					lblAbout.Text = "&nbsp;"
				End If
			Else
				hlGroupPicture.Visible = False
				hlGroupName.Visible = False
				hlCategory.Visible = False
				hlViewGroup.Visible = False
				lblSeparator.Visible = False
				hlJoinGroup.Visible = False
				lblGroupType.Visible = False
				lblCreated.Visible = False
				lblLocation.Visible = False
				lblAbout.Visible = False
				lblName.Text = Me.GetPageConstText(htPageConstants, "CONST_NoFeaturedGroup_TEXT")
				lblCategory.Visible = False
				lblType.Visible = False
				lblCreatedDate.Visible = False
				lblLocationName.Visible = False
				lblAboutGroup.Visible = False
			End If

			' List categories in two columns
			Dim tmpCategoriesCount As Integer = categoriesCount / 2
			If tmpCategoriesCount * 2 <> categoriesCount Then
				System.Math.Max(System.Threading.Interlocked.Increment(tmpCategoriesCount),tmpCategoriesCount - 1)
			End If
			Dim i As Integer = 0
			While i < tmpCategoriesCount
				Dim hlCompany1 As New HyperLink()
				Dim lblGroupsCount1 As New Label()
				tmpCategory1 = DirectCast(Constants.CATEGORIES.List(i), Categories.Category)
				hlCompany1.Text = tmpCategory1.Name
				lblGroupsCount1.Text = " (" + tmpCategory1.GroupsCount + ")"
				hlCompany1.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + tmpCategory1.ID

				Dim hlCompany2 As New HyperLink()
				Dim lblGroupsCount2 As New Label()
				If tmpCategoriesCount + i < categoriesCount Then
					tmpCategory2 = DirectCast(Constants.CATEGORIES.List(tmpCategoriesCount + i), Categories.Category)
					hlCompany2.Text = tmpCategory2.Name
					lblGroupsCount2.Text = " (" + tmpCategory2.GroupsCount + ")"
					hlCompany2.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + tmpCategory2.ID
					hlCompany1.CssClass = "main_text_bold"
					hlCompany2.CssClass = "main_text_bold"
				End If

				addTableRow(hlCompany1, lblGroupsCount1, hlCompany2, lblGroupsCount2)
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While
		End Sub

		' add row to categories table
		Private Sub addTableRow(ByVal ctlName1 As Control, ByVal ctlName2 As Control, ByVal ctlName3 As Control, ByVal ctlName4 As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			td1.Controls.Add(ctlName1)
			td1.Controls.Add(ctlName2)
			tr.Cells.Add(td1)

			Dim td2 As New TableCell()
			td2.Controls.Add(ctlName3)
			td2.Controls.Add(ctlName4)
			tr.Cells.Add(td2)

			tblCategories.Rows.Add(tr)
		End Sub
		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
		End Sub
#End Region

		Protected Sub lbJoin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.CREATE_GROUP)
		End Sub

		Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Session(Constants.ssnAdvGroupSearchFilter) = Nothing
			Response.Redirect(Constants.GROUP_SEARCH_RESULTS + "?" + Constants.KEYWORD_PARAM + "=" + Request.Params(txtKeyword.UniqueID))
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable frmGroupCategories.
		====================
		Public ReadOnly Property frmGroupCategories() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_frmGroupCategories
			End Get
		End Property
		'set { Migrated_frmGroupCategories = value; }
	End Class
End Namespace






